<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="/css/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="/css/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
    <!--<link href="/css/bootstrap-responsive.css" rel="stylesheet" media="screen">-->
    <link rel="stylesheet" type="text/css" href="/css/style.css">
    <script src="/lib/jq/jquery-2.1.1.min.js"></script>
    <script src="/css/bootstrap/js/bootstrap.min.js"></script>
    <!--<script src="/lib/jq/bootstrap.min.js"></script>-->
    <!--<script type="text/javascript" src="/js/bootstrap-paginator.min.js"></script>-->
    <!--<script type="text/javascript" src="/js/bootstrapPaginator/bootstrap-paginator.min.js"></script>-->
    <script type="text/javascript">
        $(function () {

//获得浏览器参数
            $.extend({
                getUrlVars: function () {
                    var vars = [], hash;
                    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                    for (var i = 0; i < hashes.length; i++) {
                        hash = hashes[i].split('=');
                        vars.push(hash[0]);
                        vars[hash[0]] = hash[1];
                    }
                    return vars;
                },
                getUrlVar: function (name) {
                    return $.getUrlVars()[name];
                }
            });

//封装浏览器参数
            var composeUrlParams = function () {
                var param = '';
                $.each($.getUrlVars(), function (i, item) {
                    if (item != 'p') {
                        var val = $.getUrlVar(item);
                        if (val) param += "&" + item + "=" + val;
                    }
                });
                return param;
            }

//分页功能
            var options = {
                currentPage:1,
                <!--currentPage:- page.num >,-->
                totalPages:2,
                <!--totalPages:- page.pageCount >,-->
                numberOfPages: 5,
                pageUrl: function (type, page, current) {    //页面跳转
                    <!--if (page !=- page.num >) {-->
                        return '/box_management/code?num=' + page + '&&sim=ok';
//                    }

                }
            }
//            $('#page1').bootstrapPaginator(options);
        })
    </script>
</head>
<body style="margin:15px;">
<div id="lert"></div>
<% if (success) { %>
<div class="alert alert-success">
    <h4><%= success %></h4>
</div>
<% } %>
<% if (error) { %>
<div class="alert alert-error">
    <h4><%= error %></h4>
</div>
<% } %>
<legend>素材管理</legend>
<div style="margin-bottom:15px;">
    <a href="/material/add" style="text-decoration: none">
        <input type="button"
               style="width:55px;height:30px;background-color:#DBDBDB;border:1px solid #DBDBDB;border-radius:3px;"
               value="新增"/>
    </a>

    <!--<input type="button" style="width:55px;height:30px;background-color:#DBDBDB;border:1px solid #DBDBDB;border-radius:3px;" value="打印" onclick="Allprint()"/>-->
</div>
<div class="container" style="background-color: #F5F5F5;">
    <div class="row">
        <div class="col-md-12" style="margin-top: 10px;">
            <input type="button"
                   style="width:55px;height:30px;background-color:#DBDBDB;border:1px solid #DBDBDB;border-radius:3px;"
                   name="checkAll" value="全选" onclick="checkAll('imgschk')"/>
            <input type="button"
                   style="width:55px;height:30px;background-color:#DBDBDB;border:1px solid #DBDBDB;border-radius:3px;"
                   value="取消" onclick="reverseSelect('imgschk')"/>
            <input type="button"
                   style="width:100px;height:30px;background-color:#DBDBDB;border:1px solid #DBDBDB;border-radius:3px;"
                   value="删除选中" onclick="remove()"/>
        </div>
        <%if(arr){arr.forEach(function(imgurl,index){%>
            <div class="col-sm-2 col-md-2 col-lg-2" style="margin: 5px 0 5px 0;">
                <img src="<%=domain+imgurl%>?imageView2/1/w/100/h/100">
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="imgschk" value="<%=imgurl%>">
                    </label>
                </div>
            </div>
        <%})}%>
        <br>

    </div>
    <div class="row">
        <h3>&nbsp;&nbsp;选择箱子号码</h3>
        <div class="col-md-12">
            <input type="button"
                   style="width:55px;height:30px;background-color:#DBDBDB;border:1px solid #DBDBDB;border-radius:3px;"
                   name="checkAll" value="全选" onclick="checkAll('simschk')"/>
            <input type="button"
                   style="width:55px;height:30px;background-color:#DBDBDB;border:1px solid #DBDBDB;border-radius:3px;"
                   value="取消" onclick="reverseSelect('simschk')"/>
        </div>
        <%sims.forEach(function(sim,index){%>
        <div class="col-sm-2 col-md-2 col-lg-2" style="margin: 5px 0 5px 0;">
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="simschk" value="<%=sim._id%>">
                    <%=sim.sim%>
                </label>
            </div>
        </div>
        <%})%>
        <div class="col-sm-offset-4 col-sm-4" style="margin-top: 15px;margin-bottom: 20px;">
            <button type="button" class="btn btn-default btn-block" onclick="updateSim()">提交(设置摇一摇广告)</button>
        </div>
    </div>
</div>

<div class="span12">
    <div id="page1" style="margin-bottom:0"></div>
</div>

<script>

    function checkAll(name){
        $("[name="+name+"]").attr("checked",'true');//全选
    }
    function reverseSelect(name){
        $("[name="+name+"]").removeAttr("checked");
    }

    function updateSim(){
        var imgschk = "";
        $("[name='imgschk']:checked").each(function(i){
            imgschk += ($(this).val()+",");
        });
        var simschk = "";
        $("[name='simschk']:checked").each(function(i){
            simschk += ($(this).val()+",");
        });
        $.post('/material/updateSim',{
            imgs:imgschk.substring(0,imgschk.length-1),
            sims:simschk.substring(0,simschk.length-1)
        },function(result){
            if(result.msg){
                alert('设置成功！');
            }else{
                alert('设置失败！');
            }
        });
    }

    function remove(){
        var r=confirm("确定吗？");
        if (r==true){

            var imgschk = "";
            $("[name='imgschk']:checked").each(function(i){
                imgschk += ($(this).val()+",");
            });

            $.post('/material/remove',{
                imgs:imgschk.substring(0,imgschk.length-1)
            },function(result){
                if(result.msg){
                    alert('删除成功！');
                    window.location.reload(true);
                }else{
                    alert('删除失败！');
                }
            });
        }

    }
</script>

</body>

</html>